import React from 'react'
import Item from './OrderItem'
import { connectOrder } from '../../container/order/connectOrder'

class OrderPayList extends React.Component {
	constructor(props) {
		super(props)
		this.state = {
			fetched: false,
			orderList: []
		}
    }
    componentDidMount(){
        this.props.orderActions.showOrder(0);
        this.setState({
        	fetched: true
        })
	}
	componentWillReceiveProps(nextProps) {
        if(nextProps.order.isFetched == true && this.state.fetched == true) {
            this.setState({
                orderList: nextProps.order.orderData,
                fetched: false
            })
        }
    }
	render() {
        const { orderData, orderDetail, detailisFetched, isFetched } = this.props.order
        const { showOrderDetail } = this.props.orderActions
        return (
            <div>
                {
                    orderData.map(function(item,i){
                    return(
                        <Item
                            orderId={item.orderId}
                            key={i}
                            showOrderDetail={showOrderDetail}
                            orderDetail={orderDetail}
                            detailisFetched={detailisFetched}
                            orderData={item}
                        />
                    )
                })}
            </div>

        );
	}
}
export default connectOrder(OrderPayList)